﻿using System;

using System.Collections.Generic;
using System.Text;
using System.IO;
using RecorderSample.View;
using DirectUI.Mobile.UI.Controls;
using OpenNETCF.Media.WaveAudio;
namespace RecorderSample.Controller
{
  public   class AudioRecordControler:IDisposable
    {
      public  void Dispose(){
        
      }
     // private WaveIn _audioRecord;
      private Recorder _audioRecord;
      private Page view;
      public AudioRecordControler(Page targetView)
      {
        //  _audioRecord = new RecorderSample();
          //_audioRecord.Preload(120000, 256 * 1024);
          view = targetView;
      }
      public void Start(string fileName)
      {
          //_audioRecord.Start();
         
              _fileName = fileName;
              FileStream fs = new FileStream(_fileName, FileMode.OpenOrCreate);
              _audioRecord = new Recorder();
           //  _audioRecord.RecordFor(fs, 120);
              _audioRecord.RecordFor(fs, 120, SoundFormats.Stereo16bit11kHz);
         
      }
      public void Stop()
      {
      
          _audioRecord.Stop();
  
      }
      private string _fileName;
      public void Close()
      {
         
         // _audioRecord.Save(fileName);
          AudioItem item = new AudioItem();
          item.FileName = _fileName;
          ((AudioItemListPage)((PageManager)view.Container).Pages["AudioList"]).AddItem(item);
          ((PageManager)view.Container).Switch("AudioList", Transition.ShiftRight);
       
      }
     
     
    }
}
